//============================================================================
//
// saZoneManager.js
// ----------------
//
// This file is part of the API for the s-audit internals. This module
// performs zone management utiltites, accessed by the "zone" subcommand
// from the CLI. Each function returns a simple object, which is presented
// by a callback in the client layer for presentation.
//
//============================================================================

// We need a database connection and a config file.

var sqlite3 = require('sqlite3').verbose();
var config = require('jsonconfig');

config.load(['config/config.json']);

// Get a database connection and make sure foreign keys are enforced. The
// path to the database file is in the config file.

var db = new sqlite3.Database(config.DB, function() {
    db.run('PRAGMA foreign_keys=on');
});

//----------------------------------------------------------------------------
//

module.exports = {

	zoneParent: function(zone, callback) {

		// Get an object which lists zones who have a local zone called
		// 'zone'

		db.all('SELECT hosts.hostname FROM zones, hosts WHERE \
		zones.zone_name=? AND zones.parent = hosts.id ORDER BY \
		hosts.hostname', zone, callback);
	}


}
